/**
 * Created by Flower付成华 on 2018/5/15.
 */

var bookdata;
var mulu;//全局的一个目录对象
var curbookid = "";//保存当前的bookid
var rootpath = "";//所有文件依赖的根路径，通过客户端传递过来
var playstate = 0;//默认的播放类型， 0：单句，1：本课  2：复读 3：连续 4：查词  
var audioHandler = null;
var strs = [];
var curpindex = 0;
var curpagenum = 0;
var curobject;
var ispause = 0;//是否暂停
var curtime;//当前的 settimeout
var istranslation = false;
var checkplay = false;//判断当前是否为点击播放音频，还是自动播放音频
var curalltime = 5;//默认的播放音频的时间

var curtrans = "";//当前选中的解释

var read_text = "";//当前正在读取的的文本内容，可能是英文，可能是汉文


var cur_volume = 50;//当前音量是多少
var isshowvolume = false;//是否显示开启音量
var isshowchecked = false;//是否显示可点击选读框
var isreadingover = false;//判断是否已经读取完了


var up_test_id = "";
var lastcurtime = 3;//最后一次的音频有多长
var lastscore = 0;//最后一次评分是多少
var lastscoreDetails = "";//最后一次的评分详情
var lastpageindex = 0;//上一次的页数，初始为0，每次滚动赋值
var last_read_curcontent = "";//当前阅读的选框内容



var page_divs = new Array();//所有页面的div对象几个，二维数组
var divs = new Array();//一个页面的div 集合对象


//录音相关
var isfollow = false;//当前是否开启了跟读模式
var record_playnum = 1;//用来判断当前课本是第几次播放，来控制播放本地录音

//key都为小写字母
var dicdata = {};

var fudu_content = new Array();//要复读的内容 
var start_du_page;//开始从几页开始复读
var end_du_page;//结束从几页开始复读
var isfuduing = false;//判断是否正在复读
var pageindex = 0;
var nextpageindex_add = 1;//下页面的index 叠加量
var cur_play_sudu = 1;//当前播放的音频速率

var position_data ;//元数据


var isviewbig = false;//当亲的view是否放大显示； 默认是正常显示
var position_datastr = "";//保存page元数据
var beforebigviewindex = 0;
var istwotouch =false;//是否是双指触摸
var start_ty1 = 0;//手指触摸的位置
var start_ty2 = 0;//手指触摸的位置
var start_tx1 = 0;//手指触摸的位置
var start_tx2 = 0;//手指触摸的位置

var end_ty1 = 0;//手指触摸的位置
var end_ty2 = 0;//手指触摸的位置
var end_tx1 = 0;//手指触摸的位置
var end_tx2 = 0;//手指触摸的位置
var touchtime = new Date().getTime();
var isdoubleclick = false;//判断是否双击了



var tempddd = '{\
    "subject": "",\
    "period": "",\
    "grade": "",\
    "book": {\
    "contents": [],\
    "pages": [{\
        "Rects": [{\
            "X": 0.092202626641651031,\
            "Y": 0.100322580645161289,\
            "Width": 0.375234521575985,\
            "Height": 0.026881720430107529,\
            "Sound": null,\
            "SoundTime": 0.0,\
            "TSound": null,\
            "TSoundTime": 0.0,\
            "Content": null,\
            "Translate": null\
        }],\
        "Index": 0,\
        "ImageName": "d97a3ea9aa50195e782bc2163138efaa"\
    }, {\
        "Rects": [ {\
            "X": 0.16197522679864609,\
            "Y": 0.26952141057934509,\
            "Width": 0.0052800791089420655,\
            "Height": 0.0,\
            "Sound": null,\
            "SoundTime": 0.0,\
            "TSound": null,\
            "TSoundTime": 0.0,\
            "Content": null,\
            "Translate": null\
        }],\
        "Index": 6,\
        "ImageName": "b7dbca74fca5baf5f5c1faff45856fc7"\
    }]\
}\
,"resource_path": "../../book8/"}';


    





//菜单的选择事件
function rightmenu_click(onthis){
    var topage = $$(onthis).attr("curpage");
    dismissRightMenu();
    // if(isNotNull(swiper)){
        var mySwiper = document.querySelector('.swiper-container').swiper;
        mySwiper.slideTo((Number(topage)-1));
    // }
    
}


//判断手机类型
window.onload = function () {

    // 跳转本地页面、前面要加上local关键字


    //初始化audio
    initAudio();

    //执行默认
    ispause = 1;

    audioHandler.pause();

    $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_play.png");

    clearBorder();

    // $("#div_container div").css('border','0px solid white');

   //获取本地的词典数据
   getDicts();
   
}


//请求获取字典函数
function getDicts(){
    var params = {
            callbacktype:'apis/dicts'
        }
            //网络请求框架，需要传入成功函数回调和 失败函数回调
            net_request('get','apis/dicts',params,dictsCallBack,errorCallBack);

}


function getAndroidAppDicts(){

    $.ajax({
                        type:'get',
                        url:"apis/dicts",
                        dataType:'json',
                        contentType:'application/x-www-form-urlencoded',
                        async:true, //设置同步传输，默认是true。true:异步 false:同步
                        beforeSend:function(){
                        },
                        success:function(data){
                           dictsCallBack(data);
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                                    //alert(XMLHttpRequest.status);
                                    //alert(XMLHttpRequest.readyState);
                                console.log('ajax请求接口失败');
                        }
                    });
}


  //成功的回调函数
    function dictsCallBack(data){
        // native_showdialog(JSON.stringify(data));
        if(isNotNull(data)){
            console.log(data);
            if(isNotNull(data.data)&&data.data.length>0){
                var arrdata = data.data;
                dicdata = {};
                for(var e=0;e<arrdata.length;e++){
                    if(isNotNull(arrdata[e].word) && isNotNull(arrdata[e].explain)){
                        var key = arrdata[e].word.toLowerCase();
                        // var key = arrdata[e].word;
                        var value = arrdata[e].explain;
                        dicdata[key] = value;
                    }
                }
            }
        }
    }

//  失败的回调函数
    function errorCallBack(data){
        console.log(data);
    }



//初始化swiper
function initPage(){


    //banner必备
    var swiper = new Swiper('.swiper-container', {
       spaceBetween:30,
       followFinger:false,
       touchAngle:50,
       touchMoveStopPropagation:false,
       centeredSlides:true,
       touchRatio:1,
       speed:300,
      
       on: {
               // slideNextTransitionStart: function () {//下一页
               //   var index = swiper.activeIndex;
               //   console.log("slideNextTransitionStart"+index);
               //   // alert(index);
               // },
               // slidePrevTransitionStart:function (){// 上一页
               //   var index = swiper.activeIndex;
               //   console.log("slidePrevTransitionStart"+index);
               //   // alert(index);
               // },
              touchStart: function(swiper,even){
                console.log('bg____touchStart;');

                    // var endx, endy;
                    // endx = even.changedTouches[0].pageX;
                    // endy = even.changedTouches[0].pageY;
                    // var direction = getDirectionBegin(startx, starty, endx, endy);
                    // $(".swiper-container").css("zIndex",99);

                    var event = event || window.event;
                    starty = event.touches[0].pageY;
                    
                    if(event.touches.length>=2){  //判断是否有两个点在屏幕上
                        start_ty1 = event.touches[0].pageY;
                        start_ty2 = event.touches[1].pageY;
                        start_tx1 = event.touches[0].pageX;
                        start_tx2 = event.touches[1].pageX;
                        istwotouch = true;
                    }else{
                        istwotouch = false;
                    };

                },
                touchMove: function(swiper,even){
                // console.log('bg____touchMove;');

                var event = event || window.event;
                // event.touches[0].pageY;

                var endx, endy;
                endx = event.changedTouches[0].pageX;
                endy = event.changedTouches[0].pageY;

                var direction = getDirectionBegin(startx, starty, endx, endy);

                if(event.touches.length>=2){  //判断是否有两个点在屏幕上
                    var x0 = event.touches[0].pageX;
                    var x1 = event.touches[1].pageX;
                    var y0 = event.touches[0].pageY;
                    var y1 = event.touches[1].pageY;
                    console.log("swiper:echangedTouches======"+endx);
                    console.log("swiper:touches0======"+x0+"=====1:  "+x1);
                    console.log("start_tx1:  "+start_tx1);
                    
                        if(start_tx1 == 0){
                            start_ty1 = y0;
                            start_ty2 = y1;
                            start_tx1 = x0;
                            start_tx2 = x1;  
                            console.log("start_tx1-after:  "+start_tx1);
                        }

                        end_ty1 = y0;
                        end_ty2 = y1;
                        end_tx1 = x0;
                        end_tx2 = x1;    
                        console.log("end_ty1"+end_ty1+"end_ty2"+end_ty2+"end_tx1"+end_tx1+"end_tx2"+end_tx2);
                        istwotouch = true;
                        //暂时关闭放大
                        // zoomInOrOut();//判断双指放大还是缩小
                }else{
                    istwotouch = false;
                };
                
            },
            touchEnd: function (swiper,even){
                dismissVolume();

                // if(istwotouch){  //判断是否有两个点在屏幕上
                    // zoomInOrOut();//判断双指放大还是缩小
                // }
                


            },
            doubleTap: function(event){
                console.log("view双击了");

                //暂时关闭放大
                // changeInOrOut();
            },
             click: function(swiper,even){
                console.log("view单击了");
                if(pageindex == 0){
                        var mySwiper = document.querySelector('.swiper-container').swiper;
                        mySwiper.slideTo(1); 
                        return;                                       
                }
             },
               slideChangeTransitionStart:function(){//先执行start
                 pageindex = swiper.activeIndex;

                console.log("slideChangeTransitionStart");

                 verisOverChapter(pageindex);//保存每次的章节数

                //上传最新的读取的章节的，上传读书进度
                 uploadPage(pageindex);

                 //保存已经阅读的页数 (保存在本地)
                 var param = {
                     type:'save_book_page',
                     bookid:curbookid+"",
                     bookpage:pageindex+""
                 };
                 //保存当前已经阅读的页数
                 send_data(param);


                 if(playstate == 2){//圈选模式
                     // alert("start_du_page:"+start_du_page +"end_du:"+end_du_page+"==="+index);
                     if(start_du_page != pageindex){
                          clearBorder();
                         // $("#div_container div").css('border','0px solid white');
                     }

                     if(isfuduing){//正在读
                         if(start_du_page == pageindex){
                            clearBorder();
                             // $("#div_container div").css('border','0px solid white');
                             $(fudu_content[0]).css('border','1px solid #0665A5');
                         }
                         if(end_du_page == pageindex){
                            clearBorder();
                             // $("#div_container div").css('border','0px solid white');
                             $(fudu_content[1]).css('border','1px solid red');
                         }
                     }else{

                         //执行默认
                         dismissRead();
                         clearBorder();
                         //动态创建btn
                         createCheckImage(pageindex);    
                     }

                     
                     return;
                 }


                 //执行默认
                 dismissRead();
                 clearBorder();
                 // $("#div_container div").css('border','0px solid white');
                 //动态创建btn
                 createCheckImage(pageindex);
                 
             }
         }

     });
}



function setGesture(el){
    var obj={}; //定义一个对象
    var istouch=false;
    var start=[];
    el.addEventListener("touchstart",function(e){
        if(e.touches.length>=2){  //判断是否有两个点在屏幕上
            istouch=true;
            start=e.touches;  //得到第一组两个点
            obj.gesturestart&&obj.gesturestart.call(el); //执行gesturestart方法
        };
    },false);
    document.addEventListener("touchmove",function(e){
        e.preventDefault();
        if(e.touches.length>=2&&istouch){
            var now=e.touches;  //得到第二组两个点
            var scale=getDistance(now[0],now[1])/getDistance(start[0],start[1]); //得到缩放比例，getDistance是勾股定理的一个方法
            var rotation=getAngle(now[0],now[1])-getAngle(start[0],start[1]);  //得到旋转角度，getAngle是得到夹角的一个方法
            e.scale=scale.toFixed(2);
            e.rotation=rotation.toFixed(2);
            obj.gesturemove&&obj.gesturemove.call(el,e);  //执行gesturemove方法
        };
    },false);
    document.addEventListener("touchend",function(e){
        if(istouch){
            istouch=false;
            obj.gestureend&&obj.gestureend.call(el);  //执行gestureend方法
        };
    },false);
    return obj;
};
function getDistance(p1, p2) {
    var x = p2.pageX - p1.pageX,
        y = p2.pageY - p1.pageY;
    return Math.sqrt((x * x) + (y * y));
};
function getAngle(p1, p2) {
    var x = p1.pageX - p2.pageX,
        y = p1.pageY- p2.pageY;
    return Math.atan2(y, x) * 180 / Math.PI;
};





//改变播放音量
function changeVolume(num){

    //暂时禁用

    $("#sound_set_div").show();
    console.log("改变："+num);
    // $("#sound_set_div_progress").height(cur_volume+"%");
    $("#sound_set_div_progress").height(Math.round(cur_volume)+"%");
    cur_volume = Number(cur_volume) - Number(num/70);
    console.log("改变音量："+Math.round(cur_volume));
    if(cur_volume > 100){
        cur_volume = 100;
    }
    if(cur_volume < 0){
        cur_volume = 0;
    }
    
    $("#sound_set_div_progress").height(Math.round(cur_volume)+"%");
    $("#v_progress").html("音量"+Math.round(cur_volume)+"%");
    audioHandler.audio.volume = Math.round(cur_volume)/100;
    

}

//关闭音量弹窗
function dismissVolume(){
    $("#sound_set_div").hide();;
    isshowvolume = false;    
}


function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "";
    var seperator2 = "";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    + "" + date.getHours() + seperator2 + date.getMinutes()
    + seperator2 + date.getSeconds();
    return currentdate;
}


var startx, starty;

    //获得角度
    function getAngle(angx, angy) {
        return Math.atan2(angy, angx) * 180 / Math.PI;
    };

    //根据起点终点返回方向 1向上 2向下 3向左 4向右 0未滑动
    function getDirection(startx, starty, endx, endy) {
        var angx = endx - startx;
        var angy = endy - starty;

        //如果滑动距离太短
        // if (Math.abs(angx) < 2 && Math.abs(angy) < 2) {
        //     return result;
        // }

        if(angx <= -5){//向左边滑动
            return 0;
        }else if(angx >5){//向右边滑动
            return 1;
        }else{
            return 2;
        }
    }


    //根据起点终点返回方向 1向上 2向下 3向左 4向右 0未滑动
    function getDirectionBegin(startx, starty, endx, endy) {
        var angx = endx - startx;
        var angy = endy - starty;
        //如果滑动距离太短
        // if (Math.abs(angx) < 2 && Math.abs(angy) < 2) {
        //     return result;
        // }
        // console.log("endy:"+endy+"starty"+starty+"angy:"+angy);

        if(isshowvolume){
            if(angy >= 1){//向下滑动
                // console.log("angy"+angy);
                //暂时关闭音量调节
                 // changeVolume(angy);
            }else if(angy <= -1){//向上滑动
                //暂时关闭音量调节
                 // changeVolume(angy);
            }else{

            }
        }

        if(angy >= 50){//开始调控音量
            isshowvolume = true;    
        }else if(angy < -50){
            isshowvolume = true;    
        }
        
    }


    function createCheckImage(pindex){
        console.log(pindex);
        if(position_data.length>0){
            for(var i = 0;i<position_data.length;i++){
                var pages = position_data[i].Rects;
                var Lesson = position_data[i].Lesson;
                if(pindex == i){
                    if(pages.length>0){

                        var imgContainer=document.getElementById("div_container");
                    // $("#div_container").html("");
                    divs = new Array();
                    for (var j = 0; j<pages.length; j++){
                        var x = pages[j].X;
                        var y = pages[j].Y;
                        var w = pages[j].Width;
                        var h = pages[j].Height;
                        var duration = pages[j].SoundTime;
                        var duration_zh = pages[j].TSoundTime;
                        var translationtips = pages[j].Translate;
                        var curtext = pages[j].Content;
                        var cursound = pages[j].Sound;
                        var cursound_zh = pages[j].TSound;
                        var duplicate = pages[j].Duplicate;
                        var curlesson = -1;
                        if(isNotNull(Lesson)){
                            curlesson = Lesson;
                        }

                        var cid;
                        var div;
                            imgContainer.style.height=100+"%";
                            div = document.createElement("div");
                            var aa = Number(i);
                            var bb = Number(j)+1;
                            cid = aa+"_"+bb;
                            div.id =cid;
                            div.setAttribute("cid",aa+"_"+bb);
                            div.setAttribute("curpage",aa+"");
                            div.setAttribute("currow",j+"");
                            div.setAttribute("pagenum",pages.length+"");

                            div.setAttribute("duration",Number(duration));
                            div.setAttribute("duration_zh",Number(duration_zh));
                            div.setAttribute("translationtips",translationtips);
                            div.setAttribute("curtext",curtext);
                            div.setAttribute("curlesson",curlesson);
                            div.setAttribute("cursound",cursound);

                            div.setAttribute("cwidth",w);
                            div.setAttribute("cheight",h);
                            div.setAttribute("ctop",y);
                            div.setAttribute("cleft",x);
                            
                            div.setAttribute("cursound_zh",cursound_zh);
                            if(isNotNull(duplicate) && duplicate){
                                div.setAttribute("duplicate",1)
                            }else{
                                div.setAttribute("duplicate",0)
                            }

                            div.backgroundColor = "white";

                            div.style.width = (w*100)+"%";
                            div.style.height = (h*100)+"%";



                            if(isshowchecked){
                            div.style.border = "1px solid #bababa";
                            }else{
                            div.style.border = "0px solid #0665A5";    
                            }
                            div.style.borderRadius = 5+'px';
                            // div.style.position="absolute";
                            div.style.zIndex = "100";
                            div.style.left=(x*100)+"%";
                            // div.style.zIndex = "100";
                            div.style.position = "absolute";
                            div.style.top=(y*100)+"%";


                            // div.style.backgroundColor="green";
                            // imgContainer.appendChild(div);
                            addDivChildByNotExist(imgContainer,div,cid);
                            






                                console.log($("#div_container").html());

                                //用来改变音量的
                                div.addEventListener('touchstart',function(){
                                    var event = event || window.event;
                                    switch(event.type){
                                        case "touchstart":
                                        startx = event.touches[0].pageX;
                                        starty = event.touches[0].pageY;
                                        // event.touches[0].pageY;
                                        
                                        if(event.touches.length>=2){  //判断是否有两个点在屏幕上
                                            start_ty1 = event.touches[0].pageY;
                                            start_ty2 = event.touches[1].pageY;
                                            start_tx1 = event.touches[0].pageX;
                                            start_tx2 = event.touches[1].pageX;    
                                            istwotouch = true;
                                        }else{
                                            istwotouch = false;
                                        };

                                        break;

                                    }
                                    
                                }, false);


                                div.addEventListener('touchend',function(){
                                    var event = event || window.event;
                                    switch(event.type){
                                        case "touchstart":
                                                    // console.log("touchstart");
                                                    break;
                                                    case "touchend":
                                                     dismissVolume();

                                                       //  if(istwotouch){  //判断是否有两个点在屏幕上
                                                                // zoomInOrOut();//判断双指放大还是缩小   
                                                        // }else{
                                                            var endx, endy;
                                                            endx = event.changedTouches[0].pageX;
                                                            endy = event.changedTouches[0].pageY;
                                                            var direction = getDirection(startx, starty, endx, endy);
                                                            // alert(direction);
                                                            switch (direction) {

                                                                case 0://左边
                                                                var mySwiper = document.querySelector('.swiper-container').swiper;
                                                                mySwiper.slideNext(500);
                                                                break;
                                                                case 1://右边

                                                                var mySwiper = document.querySelector('.swiper-container').swiper;
                                                                mySwiper.slidePrev(500);
                                                                break;
                                                                    case 2://不滑动
                                                                    break;
                                                                    default:
                                                                }
                                                        // }
                                                         

                                                   
                                                        break;
                                                        case "touchmove":
                                                        // event.preventDefault();//取消事件的默认动作
                                                        console.log("touchmove");
                                                        // $(".swiper-container").css("zIndex",102);
                                                break;
                                            }

                                        }, false);



                                //用来改变音量的
                                div.addEventListener('touchmove',function(){
                                    var event = event || window.event;
                                    switch(event.type){
                                            case "touchmove":
                                            var event = event || window.event;
                                            event.touches[0].pageY;

                                            var endx, endy;
                                            endx = event.changedTouches[0].pageX;
                                            endy = event.changedTouches[0].pageY;

                                            var direction = getDirectionBegin(startx, starty, endx, endy);
                                            if(event.touches.length>=2){  //判断是否有两个点在屏幕上
                                                var x0 = event.touches[0].pageX;
                                                var x1 = event.touches[1].pageX;
                                                var y0 = event.touches[0].pageY;
                                                var y1 = event.touches[1].pageY;
                                                console.log("echangedTouches======"+endx);
                                                console.log("touches0======"+x0+"=====1:  "+x1);
                                                console.log("start_tx1:  "+start_tx1);
                                                if(start_tx1 == 0){
                                                    start_ty1 = y0;
                                                    start_ty2 = y1;
                                                    start_tx1 = x0;
                                                    start_tx2 = x1;  
                                                }

                                                end_ty1 = y0;
                                                end_ty2 = y1;
                                                end_tx1 = x0;
                                                end_tx2 = x1;    
                                                console.log("div------end_ty1"+end_ty1+"end_ty2"+end_ty2+"end_tx1"+end_tx1+"end_tx2"+end_tx2);
                                                istwotouch = true;
                                                //暂时隐藏放大
                                                // zoomInOrOut();//判断双指放大还是缩小 
                                            }else{
                                                istwotouch = false;
                                            };

                                            break;
                                            }

                                        }, false);


                                // div.addEventListener("click", function (event){

                                //     alert("dd");
                                // },true);






                                imgContainer.onclick = function(event){
                                    console.log("imgview单击了");
                                    if(pindex == 0){
                                        var mySwiper = document.querySelector('.swiper-container').swiper;
                                        mySwiper.slideTo(1);                                        
                                        return;
                                    }

                                    //暂时关闭双击放大
                                    // if( new Date().getTime() - touchtime < 500 ){
                                    //     console.log("判断view双击了");
                                    //     isdoubleclick = true;
                                    //      changeInOrOut();
                                    // }else{
                                    //     touchtime = new Date().getTime();
                                    // }
                                }

                                div.onclick=function(event){
                                    console.log("div单击了");

                                    checkplay = true;
                                            //判断如果不是本页面的创建的div，不能点击
                                            var this_div_pageindex = $(this).attr("curpage");

                                            // alert("this_div_pageindex----"+this_div_pageindex+"pageindex:"+pageindex);
                                            if(pageindex != this_div_pageindex){
                                                return;
                                            }

                                            nextpageindex_add = 1;//每次点击，叠加量归为1

                                            if(playstate == 4){//查词功能，点击弹出内容弹窗，选择复制查词
                                                searchWords(this);
                                                return;
                                            }

                                            if(playstate == 2){//圈选 复读模式
                                                if(fudu_content.length == 0){//还没有圈选
                                                    start_du_page = Number(i);
                                                    $(this).css('border','1px solid #0665A5');
                                                    fudu_content[0] = this;
                                                    $.toast("请再选择一个复读终点");
                                                }else{
                                                    //开始复读
                                                    fudu_content[1] = this;

                                                    var a = ($(fudu_content[0]).attr("id")+"");
                                                    var b = ($(fudu_content[1]).attr("id")+"");
                                                    // alert(s_id_a+"="+s_id_b+"="+e_id_a+"="+e_id_b);
                                                    //防止开始的地点大于结束的地点
                                                    if(compareId(a,b) == 1){//a 比较大

                                                        end_du_page = start_du_page;
                                                        start_du_page = Number(i);
                                                        fudu_content[1] = fudu_content[0];
                                                        fudu_content[0] = this;

                                                        $(fudu_content[0]).css('border','1px solid #0665A5');

                                                    }else{
                                                        end_du_page = Number(i);
                                                    }

                                                    $("#div_content_bg").show();//开始禁止模式 
                                                    isfuduing = true;
                                                    reread(fudu_content[0]);  
                                                    // $(fudu_content[1]).css('border','1px solid red'); 
                                                    var mySwiper = document.querySelector('.swiper-container').swiper;
                                                    mySwiper.slideTo((Number($(fudu_content[0]).attr("curpage"))));                                        
                                                }
                                                
                                                return;
                                            }


                                            read(this);



                                    

                                };

                                //单独div对象添加到 集合中
                                if(divs.indexOf($("#"+cid)) == -1){
                                    divs[j] = $("#"+cid);
                                }
                                

                            }


                            if(page_divs.indexOf(divs) == -1){
                                page_divs[pindex] = divs;
                            }
                            

                            return;

                        }
                        

                    }

                }
            }


        }




//初始化audio
function initAudio(){

    
    // audioHandler = $$("#music_player")[0];
    audioHandler = new AudioPlayer({
     id: 'music_player'
 });

    audioHandler.on('canplay', function (totalTime, name, item) {

        // console.log(audioHandler.audio.playbackRate);
        audioHandler.play();
        $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_unplay.png");
        isreadingover = false;


        console.log('canplay');
        curalltime = totalTime;
    });



    audioHandler.on('ended' , function (){

           console.log("audioHandler ======== ended");
            audioEndFunc();

    });


    audioHandler.on('play' , function (){
        console.log('play');
        
        console.log(audioHandler.audio.playbackRate);
});

}





function audioEndFunc(){
    //每次读完上传一下学习记录
    if(!isfollow){
        uploadScore('1');    
    }

    


     var record_curalltime = Math.ceil(curalltime*1.2);
     lastcurtime = record_curalltime;
            curtime = setTimeout(function(){
                isreadingover = true;
               if(playstate == 0){
                   $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_play.png");
                   $("#div_tips").hide();

                   //判断是否需要跟读，处理跟读
                   commonFollow(record_curalltime,function(){
                        //跟读模式
                        $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_play.png");
                        $("#div_tips").hide();
                    });

             }else if(playstate == 1){//全局阅读，本课

                //老版本，只读取一页
               /*if(Number(strs[1])>=Number(curpagenum) || ispause){
                audioHandler.pause();
                $("#bottom_menu_img2").attr("src","../img/icon_play.png");
                $("#div_tips").hide();

                //判断是否需要跟读，处理跟读
                commonFollow(record_curalltime,function(){
                        //跟读模式
                        audioHandler.pause();
                        $("#bottom_menu_img2").attr("src","../img/icon_play.png");
                        $("#div_tips").hide();
                    });
                }else{

                    var ccid = strs[0]+"_"+(Number(strs[1])+1);


                    //判断是否需要跟读，处理跟读
                    commonFollow(record_curalltime,function(){
                        //跟读模式
                        read($("#"+ccid));  
                    });
                    if(isfollow){
                        return;
                    }
                        //正常阅读
                        read($("#"+ccid));    
                }*/


                   if(ispause){//暂停
                       dismissRead();
                       return;
                   }
                   var ccid = ""
                    if(Number(strs[1]) >= Number(curpagenum)){//本页面读取完了


                        ccid = (Number(strs[0])+1)+"_"+1;
                        console.log('本页面读完了，开始判断下一页的id是否存在：' + ccid);

                        var mySwiper = document.querySelector('.swiper-container').swiper;
                        // alert($("#"+ccid).attr("id"));
                        if(isNotNull($("#"+ccid).attr("curpage"))){


                            //判断是否本课读完
                            var oldccid = strs[0]+"_"+(Number(strs[1]));
                            var oldlesson = $("#"+oldccid).attr("curlesson");
                            var newlesson = $("#"+ccid).attr("curlesson");
                            console.log('下一页的页面存在，开始判断是否读完了本课：oldccid' + oldccid + 'oldlesson:' + oldlesson + 'newlesson:' + newlesson);
                            if(Number(newlesson) == -1 || Number(oldlesson) != Number(newlesson)){
                              console.log('本课都读完了，开始停止播放，dismissRead');
                                //本课读完了
                                dismissRead();

                                    //判断是否需要跟读，处理跟读
                                    commonFollow(record_curalltime,function(){
                                        dismissRead();
                                    });

                                    return;
                            }



                            //判断是否需要跟读，处理跟读
                            commonFollow(record_curalltime,function(){
                                closeBigView();
                                mySwiper = document.querySelector('.swiper-container').swiper;
                                mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));               
                                //跟读模式
                                read($("#"+ccid));    
                            });

                            if(isfollow){
                                return;
                            }
                            closeBigView();
                            mySwiper = document.querySelector('.swiper-container').swiper;
                            mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));               
                            
                        }else{


                            var nextpageindex = Number(curpindex)+Number(nextpageindex_add);
                            console.log('本页面读完了，下一页的id不存在，开始创建下一页的id:' + nextpageindex + ':nextpageindex_add' + nextpageindex_add);


                            // alert(nextpageindex);
                            createCheckImage(nextpageindex);
                            // alert($("#"+ccid).attr("id"));
                            if(isNotNull($("#"+ccid).attr("curpage"))){

                              console.log('id创建完成：' + ccid + '开始判断本课读完了没');
                              //判断是否本课读完
                              var oldccid = strs[0]+"_"+(Number(strs[1]));
                              var oldlesson = $("#"+oldccid).attr("curlesson");
                              var newlesson = $("#"+ccid).attr("curlesson");
                              console.log('下一页的页面存在，开始判断是否读完了本课：oldccid' + oldccid + 'oldlesson:' + oldlesson + 'newlesson:' + newlesson);
                              if(Number(newlesson) == -1 || Number(oldlesson) != Number(newlesson)){
                                console.log('本课都读完了，开始停止播放，dismissRead');
                                  //本课读完了
                                  dismissRead();

                                      //判断是否需要跟读，处理跟读
                                      commonFollow(record_curalltime,function(){
                                          dismissRead();
                                      });
                                      //清除无用边框
                                      clearBorder();
                                      return;
                            }




                                //判断是否需要跟读，处理跟读
                                commonFollow(record_curalltime,function(){
                                    closeBigView();
                                    mySwiper = document.querySelector('.swiper-container').swiper;
                                    mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));            
                                    // nextpageindex_add = Number(nextpageindex_add) +1;
                                    //跟读模式
                                    read($("#"+ccid));    
                                });

                                if(isfollow){
                                    return;
                                }
                                closeBigView();
                                mySwiper = document.querySelector('.swiper-container').swiper;
                                mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));            
                                // nextpageindex_add = Number(nextpageindex_add) +1;
                            }else{//读完了全部
                                dismissRead();

                                //判断是否需要跟读，处理跟读
                                commonFollow(record_curalltime,function(){
                                    dismissRead();
                                });

                                return;
                            }
                        }
                    }else{//本页面没有读完
                            ccid = strs[0]+"_"+(Number(strs[1])+1);


                            //判断是否需要跟读，处理跟读
                            commonFollow(record_curalltime,function(){
                                //跟读模式
                                read($("#"+ccid));    
                            });
                    }
                        var curpagelength = $("#"+ccid).attr("pagenum");
                        if(isfollow){//如果是录音模式，开始录制声音
                        //开始录制声音

                            return;
                        }
                        read($("#"+ccid)); 



             }else if(playstate == 2){//循环阅读，圈选复读
                // alert($(curobject).attr("cid")+"=="+$(fudu_content[1]).attr("cid")+"当前页词语数量:"+curpagenum);
                // strs = ($(curobject).attr("id")).split("_");

                if($(curobject).attr("cid") == $(fudu_content[1]).attr("cid")){//读完了,从头开始复读
                    // dismissFuDu();

                    isfuduing = true;
                    var fudu_pindex = $(fudu_content[0]).attr("curpage");
                    var fudu_pagenum = $(fudu_content[0]).attr("pagenum");
                    var mySwiper = document.querySelector('.swiper-container').swiper;
                        



                    //判断是否需要跟读，处理跟读
                    commonFollow(record_curalltime,function(){
                        closeBigView();
                        mySwiper = document.querySelector('.swiper-container').swiper;
                        mySwiper.slideTo((Number(fudu_pindex))); 

                        //跟读模式
                        //跟读模式
                        reread(fudu_content[0]);  

                    });
                    
                    if(isfollow){//如果是录音模式，开始录制声音
                    //开始录制声音
                        return;
                    }

                    // closeBigView();
                    mySwiper = document.querySelector('.swiper-container').swiper;
                    mySwiper.slideTo((Number(fudu_pindex))); 
                    reread(fudu_content[0]);  
                    // $(fudu_content[1]).css('border','1px solid red'); 
                }else{//没有读完，接着读

                    if(ispause){//暂停
                       dismissRead();
                       $("#div_content_bg").hide();
                       return;
                   }
                    var ccid = "";
                    var mySwiper = document.querySelector('.swiper-container').swiper;
                    if(Number(strs[1]) >= Number(curpagenum)){//本页面读取完了

                        ccid = (Number(strs[0])+1)+"_"+1;
                        // mySwiper.slideTo(Number($("#"+ccid).attr("curpage")),1000);           
                    }else{//本页面没有读完
                        ccid = strs[0]+"_"+(Number(strs[1])+1);
                    }


                    //判断是否需要跟读，处理跟读
                    commonFollow(record_curalltime,function(){
                        
                        if(Number(strs[1]) >= Number(curpagenum)){//本页面读取完了
                            closeBigView();
                            mySwiper = document.querySelector('.swiper-container').swiper;
                            mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));           
                        }

                        //跟读模式
                        reread($("#"+ccid));   
                    });
                    
                    if(isfollow){//如果是录音模式，开始录制声音
                    //开始录制声音
                        return;
                    }



                    if(Number(strs[1]) >= Number(curpagenum)){//本页面读取完了
                        closeBigView();
                            mySwiper = document.querySelector('.swiper-container').swiper;
                        mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));           
                    }
                    reread($("#"+ccid)); 
                }
                
             }else if(playstate == 3){//连续
                    if(ispause){//暂停
                       dismissRead();
                       return;
                   }
                   var ccid = ""
                // alert("str[1]:"+strs[1]+"--"+"curpagenum:"+curpagenum+"==");
                    if(Number(strs[1]) >= Number(curpagenum)){//本页面读取完了
                        ccid = (Number(strs[0])+1)+"_"+1;
                        var mySwiper = document.querySelector('.swiper-container').swiper;
                        // alert($("#"+ccid).attr("id"));
                        if(isNotNull($("#"+ccid).attr("curpage"))){

                            //判断是否需要跟读，处理跟读
                            commonFollow(record_curalltime,function(){
                                closeBigView();
                                mySwiper = document.querySelector('.swiper-container').swiper;
                                mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));               
                                //跟读模式
                                read($("#"+ccid));    
                            });

                            if(isfollow){
                                return;
                            }
                            closeBigView();
                            mySwiper = document.querySelector('.swiper-container').swiper;
                            mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));               
                            
                        }else{
                            var nextpageindex = Number(curpindex)+Number(nextpageindex_add);
                            console.log("nextpageindex:"+nextpageindex+"===nextpageindex_add:"+nextpageindex_add);
                            // alert(nextpageindex);
                            createCheckImage(nextpageindex);
                            // alert($("#"+ccid).attr("id"));
                            if(isNotNull($("#"+ccid).attr("curpage"))){

                                //判断是否需要跟读，处理跟读
                                commonFollow(record_curalltime,function(){
                                    closeBigView();
                            mySwiper = document.querySelector('.swiper-container').swiper;
                                    mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));            
                                    // nextpageindex_add = Number(nextpageindex_add) +1;
                                    //跟读模式
                                    read($("#"+ccid));    
                                });

                                if(isfollow){
                                    return;
                                }

                                console.log("连读开始跳转新的页面："+$("#"+ccid).attr("curpage"));
                                closeBigView();
                            mySwiper = document.querySelector('.swiper-container').swiper;
                                mySwiper.slideTo(Number($("#"+ccid).attr("curpage")));            
                                // nextpageindex_add = Number(nextpageindex_add) +1;
                            }else{//读完了全部
                                console.log("连读全部读完了");
                                dismissRead();

                                //判断是否需要跟读，处理跟读
                                commonFollow(record_curalltime,function(){
                                    dismissRead();
                                });
                                
                                return;
                            }
                        }
                        // alert("nextccid:"+Number($("#"+ccid).attr("curpage")));
                        // alert(ccid);
                    }else{//本页面没有读完
                        ccid = strs[0]+"_"+(Number(strs[1])+1);


                        //判断是否需要跟读，处理跟读
                        commonFollow(record_curalltime,function(){
                            //跟读模式
                            read($("#"+ccid));    
                        });
                    }
                    var curpagelength = $("#"+ccid).attr("pagenum");

                    
                    
                    if(isfollow){//如果是录音模式，开始录制声音
                    //开始录制声音
                        return;
                    }
                    read($("#"+ccid));    

             }else if(playstate == 4){//查词


             }else if(playstate == 5){//连续阅读单句
               if(ispause){

               }else{

                audioHandler.pause();
                //判断是否需要跟读，处理跟读
                commonFollow(record_curalltime,function(){
                    //跟读模式
                    //跟读模式
                    read(curobject);    
                });
                
                if(isfollow){//如果是录音模式，开始录制声音
                //开始录制声音
                    return;
                }
                    read(curobject);
                }
            }

        // },((curalltime*1200)/cur_play_sudu))
    },1000)
}



var nextreadcallback;
//公共的跟读
function commonFollow(ctime,nextcallback){
  nextreadcallback = nextcallback;
    if(isfollow){//如果是录音模式，开始录制声音
                        //开始录制声音
                            if(record_playnum == 1){//第一次
                                beginFollow(ctime);
                            }else if(record_playnum == 2){//第二次，开始播放本地录音
                                record_playnum = 1;
                                playRecord();

                                //往下接着读
                                if(isNotNull(nextcallback)){
                                    setTimeout(function(){

                                        nextcallback();

                                    },(ctime+2));
                                }
                            }
        return true;
    }else{
        return false;
    }
}



//停止复读模式，重新开始阅读起点和终点
function click_fududiv_bg(){
    dismissRead();
    dismissFuDu();
    clearBorder();
    closeBigView();
    playstate == 2;
    createCheckImage(pageindex);
    $.toast("已停止复读，请重新选择阅读起点和终点");
    
}






//开始重复阅读
function reread(ob){

    //全局
    curpagenum = $(ob).attr("pagenum");
    curpindex = $(ob).attr("curpage");
    curobject = ob;

    // $("#div_container div").css('border','0px solid white');
    clearBorder();



    var recurpage = Number($(ob).attr("curpage"));
    if(end_du_page == recurpage){
        $(fudu_content[1]).css('border','1px solid red');
    }
    $(ob).css('border','1px solid #0665A5');
    var strid = $(ob).attr("id")+"";
    var tips = $(ob).attr("translationtips");
    var sound = $(ob).attr("cursound");
    var sound_zh = $(ob).attr("cursound_zh");
    var playdur = $(ob).attr("duration");
    read_text = $(ob).attr("curtext");
    last_read_curcontent = $(ob).attr("curtext");
    console.log('id:'+strid);
    strs = strid.split("_");
    var msrc = rootpath+sound;
     $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_unplay.png");
     $("#div_tips").hide();
     $("#div_tips").html(tips);

     if(istranslation){
        playdur = $(ob).attr("duration_zh");
        msrc = rootpath+sound_zh;
        if(isNotNull(tips)){

            if(tips.length >= 150){
                $("#div_tips").css("font-size",15);
            }else{
                $("#div_tips").css("font-size",20);
            }

            $("#div_tips").show();    
        }
        
        read_text = tips;  



        if(!isNotNull(sound_zh)){
          //无声音乐
          msrc = 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/nosound/nosound.mp3';
          playdur = 1;
          console.log(msrc);
        }

    }else{
      if(!isNotNull(sound)){
          //无声音乐
          msrc = 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/nosound/nosound.mp3';
          playdur = 1;
          console.log(msrc);
        }
    }





    if(isIOS()){
        // msrc = msrc + "p3";
    }

    // if(!isNotNull(sound) || !isNotNull(sound_zh)){
    //     //无声音乐
    //     msrc = 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/nosound/nosound.mp3';
    //     playdur = 1;
    //     console.log(msrc);
    // }

    var list = [{
        name: strid,
        url: msrc,
        time: playdur
    }];

    //播放声音
    // $("#bgmusic").html("<source src="+msrc+">");
    // $("#bgmusic").get(0).load();

    ispause = 0;
    clearTimeout(curtime);


    // //先判断是否是重复的音频，如果是重复的音频要跳过重复音频阅读  ,并且播放状态为 1，2，3 时   ， 并且 必须为非点击播放才会自动下一句
    if(Number($(ob).attr("duplicate")) == 1 && (playstate == 1 || playstate == 2 || playstate == 3) && !checkplay){// == 1 为重复音频
        audioEndFunc();//重新阅读下句
        checkplay = false;
        return;
    };
    checkplay = false;



    audioHandler.clearList();
    audioHandler.add(list);
    audioHandler.loadIndex(0);

    if(cur_play_sudu > 1){//如果当前的速度大于1，ios 机型大于1 的速度回播放不出声音，用本地的播放器来代替播放
        var param = {
            type:'play_local_sounds',
            speed:cur_play_sudu,
            soundsrc:msrc
        };
        //开始去录音
        send_data(param);
    }
}


//开始阅读
function read(ob){

     //全局
    curpagenum = $(ob).attr("pagenum");
    curpindex = $(ob).attr("curpage");
    curobject = ob;

    // $("#div_container div").css('border','0px solid white');
    clearBorder();


    $(ob).css('border','1px solid #0665A5');
    var strid = $(ob).attr("id")+"";

    var tips = $(ob).attr("translationtips");
    var sound = $(ob).attr("cursound");
    var sound_zh = $(ob).attr("cursound_zh");
    var playdur = $(ob).attr("duration");
    read_text = $(ob).attr("curtext");
    last_read_curcontent = $(ob).attr("curtext");
    console.log('id:'+strid);
    strs = strid.split("_");


    var msrc = rootpath+sound;
     $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_unplay.png");
     $("#div_tips").hide();
     $("#div_tips").html(tips);
     if(istranslation){
        playdur = $(ob).attr("duration_zh");
        msrc = rootpath+sound_zh;
        if(isNotNull(tips)){

            if(tips.length >= 150){
                $("#div_tips").css("font-size",15);
            }else{
                $("#div_tips").css("font-size",20);
            }

            
            $("#div_tips").show();    
        }
        // $("#div_tips").show(); 
        read_text = tips;   




        if(!isNotNull(sound_zh)){
          //无声音乐
          msrc = 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/nosound/nosound.mp3';
          playdur = 1;
          console.log(msrc);
        }

    }else{
      if(!isNotNull(sound)){
          //无声音乐
          msrc = 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/nosound/nosound.mp3';
          playdur = 1;
          console.log(msrc);
        }
    }



    if(isIOS()){
        // msrc = msrc + "p3";
    }

    

    var list = [{
        name: strid,
        url: msrc,
        time: playdur
    }];

    //播放声音
    // $("#bgmusic").html("<source src="+msrc+">");
    // $("#bgmusic").get(0).load();

    ispause = 0;
    clearTimeout(curtime);


    // //先判断是否是重复的音频，如果是重复的音频要跳过重复音频阅读  ,并且播放状态为 1，2，3 时   ， 并且 必须为非点击播放才会自动下一句
    if(Number($(ob).attr("duplicate")) == 1 && (playstate == 1 || playstate == 2 || playstate == 3) && !checkplay){// == 1 为重复音频
        audioEndFunc();//重新阅读下句
        checkplay = false;
        return;
    };
    checkplay = false;
    


    audioHandler.clearList();
    audioHandler.add(list);
    audioHandler.loadIndex(0);

    if(cur_play_sudu > 1){//如果当前的速度大于1，ios 机型大于1 的速度回播放不出声音，用本地的播放器来代替播放
        var param = {
            type:'play_local_sounds',
            speed:cur_play_sudu,
            soundsrc:msrc
        };
        //开始去录音
        send_data(param);
    }

 }


//清空边框
function clearBorder(){
    if(!isshowchecked){
        $("#div_container div").css('border','0px solid white');

        
    }else{
        var divs = page_divs[pageindex];
        $("#div_container div").css('border','0px solid white');
        if(isNotNull(divs)){

            for(var i = 0;i<divs.length;i++){
                var cdiv = divs[i];
                console.log("当前页面的id："+cdiv.attr("id"));

                if(isNotNull(cdiv)){
                    if(i < Number(curpagenum) || curpagenum == 0){
                        $(cdiv).css('border','1px solid #bababa');
                    }
                    
                }
            }
        }
        
        // $("#div_container div").css('border','1px solid #bababa');

    }
}




//是否显示可点击读框
function showChecked(){
    if(!isshowchecked){
        $.toast("显示点读框");
        $("#img_showchecked").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_hand_check.png");
        isshowchecked = true;
        clearBorder();



    }else{
        $.toast("隐藏点读框");
        $("#img_showchecked").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_hand_uncheck.png");
        isshowchecked = false;
        clearBorder();
    }

    showcurcheckbox_border();
}

//放大
function showBig(){
    // if(!isviewbig){
    //     // $("#img_showbig").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_imgtwobig.png");
    // }else{
    //     // $("#img_showbig").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_imgonebig.png");
    // }
    changeInOrOut();
}


//设置当前页面的z-index最大
function setCurZIndexTop(){
     
        for(var k = 0;k<page_divs.length;k++){
            var divs = page_divs[k];       
            if(isNotNull(divs)){
                for(var i = 0;i<divs.length;i++){
                    var cdiv = divs[i];
                    if(isNotNull(cdiv)){
                        if(k == pageindex){//当前页面z-index最大
                            console.log("当前页面的优先级最高："+k+"=====");
                            $(cdiv).attr("z-index",110);
                        }else{
                            $(cdiv).attr("z-index",100);
                        }
                        
                    }
                }
            }
        }
}






 function showmenu(){
    // closeBigView();
    showblackbg();
    toshare();
}


//点击改变播放音频的状态
function readstate(){

    if(audioHandler.playing){//暂停
        ispause = 1;
        audioHandler.pause();
        $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_play.png");
        showcurcheckbox_border();
    }else{
        ispause = 0;
        showcurcheckbox_border();
        if(isNotNull(audioHandler.list)){//如果为空，默认从头开始播放

            var curpro_play = audioHandler.audio.currentTime;
            console.log("当前的播放进度是："+audioHandler.audio.currentTime);
            if(isNotNull(curpro_play) && !isNaN(curpro_play)){
                curpro_play = curpro_play - 1;
                if(curpro_play < 0){
                    curpro_play = 0;
                }
                if(!isreadingover){
                    audioHandler.audio.currentTime = curpro_play;
                }
                
            }



            audioHandler.play();
        }else{

            var cdiv = page_divs[pageindex][0];
            
            read(cdiv,pageindex,position_data[pageindex].page_data.length);
            
            
        }
        
        $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_unplay.png");
        
    }

}


//弹出层
function toshare(){
    $("#div_content_bg").hide();//关闭禁止模式 

    $(".am-share").addClass("am-modal-active"); 
    if($(".sharebg").length>0){
        $(".sharebg").addClass("sharebg-active");
    }else{
        $("body").append('<div class="sharebg"></div>');
        $(".sharebg").addClass("sharebg-active");
    }
    $(".sharebg-active,.share_btn").click(function(){
        $(".am-share").removeClass("am-modal-active");  
        setTimeout(function(){
            $(".sharebg-active").removeClass("sharebg-active"); 
            $(".sharebg").remove(); 
        },300);
    })

} 

function menu1(){
    $("#div_words_bg").hide();
    $("#li_menu4").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu5_off.png)");
    $("#li_menu9").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu6_off.png)");

    $("#li_menu4").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu1_on.png)");
    $(".am-share").removeClass("am-modal-active");  
    setTimeout(function(){
        $(".sharebg-active").removeClass("sharebg-active"); 
        $(".sharebg").remove(); 
    },300);
    playstate = 0;

    if(isfuduing){//判断是否正在复读
        dismissFuDu();
    }
    dismissRead();
}  

function menu2(){
    if(isviewbig){
        // bigViewTips();
        // return;
    }
    $("#div_words_bg").hide();
    $("#li_menu4").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu1_off.png)");
    $("#li_menu5").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu2_off.png)");
    $("#li_menu6").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu3_off.png)");
    $("#li_menu7").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu4_off.png)");
    $("#li_menu8").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu5_off.png)");
    $("#li_menu9").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu6_off.png)");

    $("#li_menu5").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu2_on.png)");
    $(".am-share").removeClass("am-modal-active");  
    setTimeout(function(){
        $(".sharebg-active").removeClass("sharebg-active"); 
        $(".sharebg").remove(); 
    },300);

    playstate = 1;

            if(isfuduing){//判断是否正在复读
                dismissFuDu();
            }
            dismissRead();
        } 

        function menu3(){
            if(isviewbig){
                bigViewTips();
                return;
            }
            $("#div_words_bg").hide();
            $("#li_menu4").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu1_off.png)");
            $("#li_menu5").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu2_off.png)");
            $("#li_menu6").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu3_off.png)");
            $("#li_menu7").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu4_off.png)");
            $("#li_menu8").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu5_off.png)");
            $("#li_menu9").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu6_off.png)");

            $("#li_menu6").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu3_on.png)");
            $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            // playstate = 5;
            playstate = 2;
            // $("#div_container div").css('border','0px solid white');
            clearBorder();

            fudu_content = new Array();

            if(isfuduing){//判断是否正在复读
                dismissFuDu();
            }
            dismissRead();
        } 


        function menu4(){
            if(isviewbig){
                // bigViewTips();
                // return;
            }
            $("#div_words_bg").hide();
            $("#li_menu4").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu1_off.png)");
            $("#li_menu5").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu2_off.png)");
            $("#li_menu6").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu3_off.png)");
            $("#li_menu7").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu4_off.png)");
            $("#li_menu8").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu5_off.png)");
            $("#li_menu9").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu6_off.png)");

            $("#li_menu7").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu4_on.png)");
            $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            playstate = 3;

            if(isfuduing){//判断是否正在复读
                dismissFuDu();
            }
            dismissRead();
        }

        function menu5(){

            $("#div_words_bg").hide();
            $("#li_menu4").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu1_off.png)");
            $("#li_menu5").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu2_off.png)");
            $("#li_menu6").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu3_off.png)");
            $("#li_menu7").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu4_off.png)");
            $("#li_menu8").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu5_off.png)");
            $("#li_menu9").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu6_off.png)");

            $("#li_menu8").css("background-image","url(https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_menu5_on.png)");

            $(".am-share").removeClass("am-modal-active");  
            setTimeout(function(){
                $(".sharebg-active").removeClass("sharebg-active"); 
                $(".sharebg").remove(); 
            },300);

            playstate = 4;

            if(isfuduing){//判断是否正在复读
                dismissFuDu();
            }
            dismissRead();
        }


        function menu6(){
            $("#div_words_bg").hide();
    // $("#li_menu4").css("background-image","url(../img/icon_menu1_off.png)");
    // $("#li_menu5").css("background-image","url(../img/icon_menu2_off.png)");
    // $("#li_menu6").css("background-image","url(../img/icon_menu3_off.png)");
    // $("#li_menu7").css("background-image","url(../img/icon_menu4_off.png)");
    // $("#li_menu8").css("background-image","url(../img/icon_menu5_off.png)");
    // $("#li_menu9").css("background-image","url(../img/icon_menu6_off.png)");

    // $("#li_menu9").css("background-image","url(../img/icon_menu6_on.png)");

    $(".am-share").removeClass("am-modal-active");  
    setTimeout(function(){
        $(".sharebg-active").removeClass("sharebg-active"); 
        $(".sharebg").remove(); 
    },300);

            // playstate = 0;
            showChangeSudu();
            if(isfuduing){//判断是否正在复读
                dismissFuDu();
            }
            // dismissRead();
        }


//开始点击查词,弹出框框
function searchWords(ob){

    var str_tips_arr = $(ob).attr("title")+"";
    var text = $(ob).attr("curtext");
    curtrans = $(ob).attr("translationtips");
    if(isNotNull(text)){
      $("#div_words_dialog_content").html(text);
    }else{
      $("#div_words_dialog_content").html('');
    }
    
    $("#div_words_dialog").show();
    showblackbg();

    if(isIOS()){
    }else{//如果是安卓手机，长按查词可能没有查词按钮，也可以选中文字后点击 “图书” 两字进行查词
    	var toptips = "（如果长按文字没有弹出 '查词' 选项，也可以在长按选中文字后点击顶部 '图书' 文字进行查词）";
    	$("#search_words_toptips").html(toptips);
    }

    if(!isIOS()){
    //获取android的字典数据,android字典数据太长，发送不过来
        getAndroidAppDicts();
    }


}

//关闭弹窗
function closeDialog(){
    $("#div_words_dialog").hide();
    $("#div_words_bg").hide();
}

//获取选中的文本，执行查词功能
function getCurText(){

    var text = window.getSelection().toString();
    //转换成小写
    text = text.toLowerCase();
    //去掉前后空格
    text = $.trim(text);

    if(!isNotNull(text)){
    	return;
    }
    // native_showdialog(JSON.stringify(dicdata));
    // console.log(dicdata);

    if((Object.keys(dicdata)).indexOf(text) == -1){
        //开始弹出查词的框
        // alert("查词解释：  暂无此解释");
//         $.alert('暂无此解释', '查词解释');
        native_showdialog("暂无此解释");
}else{
        //开始弹出查词的框
//        $.alert(" "+text+": "+dicdata[text], '查词解释');
        // alert("查词解释：  "+text+": "+dicdata[text]);
        // native_showdialog(" "+text+": "+dicdata[text]);
        native_showdialog(" " + dicdata[text] + " ");
    }
    
}

//停止阅读，比如切换菜单类型跟暂停时
function dismissRead(){
    //执行默认
    ispause = 1;
    
    $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_play.png");
    $("#div_tips").hide();

    if(audioHandler == null){
      console.log("dismissRead，重新初始化initAudio");
      initAudio();
    }
    audioHandler.pause();
}

//停止复读
function dismissFuDu(){
    isfuduing = false;
    audioHandler.pause();
    $("#bottom_menu_img2").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/icon_play.png");
    $("#div_tips").hide();
    $("#div_content_bg").hide();
    // $("#div_container div").css('border','0px solid white');
    clearBorder();
    fudu_content = new Array();
}

//显示目录菜单
function showRightMenu(){

    closeBigView();
    $("#div_right").show();
    showblackbg();
    $("#div_words_dialog").hide();
    $(".am-share").removeClass("am-modal-active");  
    setTimeout(function(){
        $(".sharebg-active").removeClass("sharebg-active"); 
        $(".sharebg").remove(); 
    },300);

    var ddd = page_divs[pageindex][0];
    // console.log("输出div参数0："+$(ddd).height());
}

//关闭目录菜单
function dismissRightMenu(){

    $("#div_right").hide();
    $("#div_words_bg").hide();  

}


//弹出 速度设置层
function showChangeSudu(){
    $("#div_chang_sudu").show();
    showblackbg();
}

//隐藏速度层
function hideChangeSudu(){
    $("#div_chang_sudu").hide();
    // var audioElm = document.getElementById("music_player"); // Audio element
    var sudu = $$(".single-slider").val();   
    if(sudu == 6){//中
        audioHandler.audio.defaultPlaybackRate = 1;
        audioHandler.audio.playbackRate = 1;
        cur_play_sudu = 1;
    }else if(sudu > 6){//快
        var csd = (sudu - 6)*0.1;
        audioHandler.audio.defaultPlaybackRate = (1+csd);
        audioHandler.audio.playbackRate = (1+csd);
        cur_play_sudu = (1+csd);
    }else if(sudu < 6){//慢
        var csd = (6-sudu)*0.1;
        audioHandler.audio.defaultPlaybackRate = (1-csd);
        audioHandler.audio.playbackRate = (1-csd);
        cur_play_sudu = (1-csd);
    }
    console.log("当前的播放速度："+audioHandler.audio.playbackRate);
    // alert(audioElm.playbackRate);
}



//跟读，开启跟读模式
function follow(){
    // closeBigView();
    if(isfollow){
        $.toast("已关闭跟读模式");
        $("#bottom_menu_img4").attr('src', 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_icon_replay_off.png'); 
        isfollow = false;
    }else{
        if(playstate == 0){//只有单句才能跟读
          $.toast("已开启跟读模式");
          $("#bottom_menu_img4").attr('src', 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_icon_replay_on.png'); 
          isfollow = true;
          record_playnum = 1;  
        }else{
          $.toast("只有单句才能开启跟读模式");
        }
        
    }

}


//去播放跟读模式下，开始录音然后播放
function beginFollow(ptime){
    $.toast("开始录音");
    var param = {
        type:'begin_record',
        time:ptime
    };
    //开始去录音
    send_data(param);

}


//结束录音了，开始播放刚才的课本然后再次播放录音
function stopRecord(){
    //录音结束，再次播放上一次的声音，调用全局的一个播放
    if(ispause){          
    }else{
        record_playnum = 2;
        $.toast("开始播放");
        audioHandler.pause();
        read(curobject,curpindex,curpagenum);
    }
}

//结束课本文件后，开始去播放本地的录音，结束后，next
function playRecord(){
    var iszh = "0";
    var showscore = "0";
    if(playstate == 0){//只有单句才显示评分
        showscore = "1";
    }
    if(istranslation){
        iszh = "1"
    }

    var param = {
        type:'play_record',
        curtext:read_text,
        iszh:iszh,
        showscore:showscore
    };
    //开始去录音
    send_data(param);
}


//跟读结束，传过来评分结果
function endTestResult(data){
  // if(isNotNull(data)){
  //     lastscoreDetails  = data;
  //     var read_chapter = $$(data).find("read_chapter");
  //     var read_score = $$(read_chapter[0]).attr("total_score");
  //     var read_content = $$(read_chapter[0]).attr("content");
  //     // $.alert(read_score+"==="+read_content);

  //     $$(".dislog").css("display","block");
  //     $$("#gendu_content").html(read_content);
  //     lastscore = parseInt(read_score*20);
  //     $$("#gendu_score").html(parseInt(read_score*20)+"分");

  //     // var words = $$(data).find("word");
  //     // var resultdata = 
  //     // for(var i = 0;i<words.length;i++){
  //     //     var word = words[i];
  //     // }
  //     // $.alert(read_chapter[0].attr("total_score"));
      
  // }




  if(isNotNull(data)){
     // alert(data);
     var result = {};
     if(data.indexOf("xml_result") != -1){//需要用xml的方式读取

        var read_chapter = $$(data).find("read_chapter");
      var read_score = $$(read_chapter[0]).attr("total_score");
      var read_content = $$(read_chapter[0]).attr("content");
      // $.alert(read_score+"==="+read_content);
      // alert(read_score+"==="+read_content);
      $$(".dislog").css("display","block");
      $$("#gendu_content").html(read_content);
      lastscore = parseInt(read_score*20);
      $$("#gendu_score").html(parseInt(read_score*20)+"分");



      //封装json
      var xmlsentence = $$(read_chapter[0]).find("sentence");
      var words = new Array();
      for(var k=0;k<xmlsentence.length;k++){
        var wordsxml = $$(xmlsentence[k]).find("word");
        for(var j = 0;j<wordsxml.length;j++){
                var itemcontent = $$(wordsxml[j]).attr("content");
                var itemscore = $$(wordsxml[j]).attr("total_score");

                var xmlword = {};
                xmlword.content = itemcontent;
                xmlword.score = Number(itemscore)*20;
                words.push(xmlword);
          }
      }
      

      result.chapter_content = read_content;
      result.chapter_score = Number(read_score)*20;
      result.words = words;

     }else{//json方式读取

        if(isNotNull(data)){
            var jsondata = JSON.parse(data);
            if(isNotNull(jsondata) && isNotNull(jsondata.data) && isNotNull(jsondata.data.read_sentence)){
                var tscore = jsondata.data.read_sentence.rec_paper.read_chapter.total_score;
                var tcontent = jsondata.data.read_sentence.rec_paper.read_chapter.content;
                var twords = jsondata.data.read_sentence.rec_paper.read_chapter.sentence.word;
                var twordsarr = new Array();
                if(isNotNull(twords)){
                    for(var ii = 0;ii<twords.length;ii++){
                        var tword = twords[ii];
                        var newtword = {};
                        newtword.content = tword.content;
                        newtword.score = tword.total_score;
                        twordsarr.push(newtword);
                    }
                }
                result.chapter_content = tcontent;
                result.chapter_score = tscore;
                result.words = twordsarr;

                $$(".dislog").css("display","block");
                $$("#gendu_content").html(tcontent);
                lastscore = parseInt(tscore);
                $$("#gendu_score").html(parseInt(tscore)+"分");
            }
        }

    
      // $.alert(read_score+"==="+read_content);
      // alert(read_score+"==="+read_content);
      
     }



      lastscoreDetails  = JSON.stringify(result);
      
  }
}

//跟读，重新跟读
function rereadReread(){
$$(".dislog").css("display","none");//隐藏评分框
//开始重新读
commonFollow(lastcurtime,nextreadcallback);
}

//跟读， 提交成绩
function rereadSubmit(){
$$(".dislog").css("display","none");//隐藏评分框



//接着自动往下读(目前不要自动往下读)
if(isNotNull(nextreadcallback)){
    // nextreadcallback();
}


//开始上传分数成绩
uploadScore('0');


}

//上传接口本次阅读的分数成绩
function uploadScore(islisten){


var strsection = "";

if(mulu != null){

        if(mulu.length>1){//证明章数大于2章

            for(var i = 0;i<mulu.length;i++){
              var item;
              if(i == mulu.length-1){
                item = mulu[i];
              }else{
                item = mulu[i+1];
              }
              var preitem = mulu[i];
              if(item != null && pageindex < item.PageNo && preitem != null){//判断是否为前一页的页码
                strsection = preitem.Text;
                break;
              }

              if(item != null && pageindex >= item.PageNo){//最后一章
                strsection = item.Text;
                break;
              } 
            }
        }else{
            strsection = mulu[0].Text;
        }


    }else{
        strsection = '';
    }

    var ctg_id = '0';
    // bookdata.bookinfo.book.category_id
    if(isNotNull(bookdata.bookinfo) && isNotNull(bookdata.bookinfo.book) && isNotNull(bookdata.bookinfo.book.category_id)){
        ctg_id = bookdata.bookinfo.book.category_id;
    }
  var param = {};


  if(islisten == '0'){

    param = {
        test_id:up_test_id,
        category_id:ctg_id,
        book_id:bookdata.book_id,
        section:strsection,
        point:lastscore,
        is_listen_test:islisten,
        detail:lastscoreDetails

      };

  }else{

    param = {
        test_id:up_test_id,
        category_id:ctg_id,
        book_id:bookdata.book_id,
        section:strsection,
        point:'0',
        is_listen_test:islisten,
        detail:last_read_curcontent,
        isshowdialog:'0'
      };

  }

  var url = 'apis/uploadtest';

  net_request('post',url,param,uploadScoreCallBack,errorCallBack);
}



//上传音频成功的回调
function uploadScoreCallBack(data){
  // alert(JSON.stringify(data));
  if(isNotNull(data) && data.success){//上传音频成功
    // alert(data.data.id);
     up_test_id = data.data.id;//保存最新的test_id，如果跨章，text_id 重置为空
  }
}



//每次上传当前页的
function uploadPage(pageindex){

    var param = {
        goods_id:bookdata.book_id,
        type:'0',
        readpage:pageindex+"",
        isshowdialog:'0'
      };

  var url = 'apis/updateUserBook';
  net_request('post',url,param,uploadPageCallBack,errorCallBack);
}


//上传当前读书的进度接口回调
function uploadPageCallBack(data){
    // $.alert(JSON.stringify(data));
}



// http://dict-co.iciba.com/api/dictionary.php?w=go&key=DE5EB7C205E95AB2884CB14102E64369&type=json
//是否需要翻译提示
function translation_change(){
    // closeBigView();
    if(istranslation){
        $.toast("已关闭翻译");
        $("#bottom_menu_img3").attr('src', 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_translation_off.png'); 
        istranslation = false;

    }else{
        $.toast("已开启翻译");
        $("#bottom_menu_img3").attr('src', 'https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_translation_on.png'); 
        istranslation = true;

    }
}


//添加子元素
function addDivChildByNotExist(fatherdiv,strchild,cid){

    if(isNotNull(fatherdiv)){
        if($("#"+cid).length > 0){
            console.log("remove")
            $("#"+cid).remove();
        }
        fatherdiv.appendChild(strchild);
    }
}


//判断当前的页数是否已经跨越之前的章
function verisOverChapter(vcindex){

    var isover = false;

    var curchapter = getCurChapter(vcindex);//获取当前的章数，判断是否跨章
    var lastchapter = getCurChapter(lastpageindex);
    if(curchapter != lastchapter){
        // $.toast("您已经跨章了，curchapter="+curchapter + "==lastchapter:" + lastchapter);
        isover = true;
        up_test_id  = "";//如果跨章，每次的test_id 重置为”“
    }
    lastpageindex = vcindex;
    return isover;
}




//获取当前的章节
function getCurChapter(vcindex){    
    var curchapter = 0;
    if(mulu != null){

        if(mulu.length>1){//证明章数大于1章

            for(var i = 0;i<mulu.length;i++){ 
              var item;
              if(i == mulu.length-1){
                item = mulu[i];
              }else{
                item = mulu[i+1];
              }
              var preitem = mulu[i];
              if(item != null && vcindex < item.PageNo && preitem != null){//判断是否为前一页的页码
                curchapter = preitem.PageNo;//当前页数的章
                return curchapter;
              }

              if(item != null && vcindex >= item.PageNo){//最后一章
                curchapter = item.PageNo;//当前页数的章
                return curchapter;
              }              

            }
        }else{
            curchapter = mulu[0].PageNo;
        }


    }else{
        curchapter = 0;
    }
    return curchapter;
}


var lastscale = 1;//上一次的缩放比例
//判断双指是放大还是缩小
function zoomInOrOut(){
    // alert("end------end_ty1: "+end_ty1+"end_ty2: "+end_ty2+"end_tx1: "+end_tx1+"end_tx2: "+end_tx2 + "start_tx1: "+start_tx1+ "start_tx2: "+ start_tx2 + "start_ty1: "+ start_ty1 + "start_ty2: "+start_ty2)
    console.log("end------end_ty1: "+end_ty1+"end_ty2: "+end_ty2+"end_tx1: "+end_tx1+"end_tx2: "+end_tx2 + "start_tx1: "+start_tx1+ "start_tx2: "+ start_tx2 + "start_ty1: "+ start_ty1 + "start_ty2: "+start_ty2);
    // end_ty1: 296.727294921875end_ty2: 469.0909118652344end_tx1: 284end_tx2: 62.90909194946289start_tx1: 284start_tx2: 62.90909194946289start_ty1: 296.727294921875start_ty2: 469.0909118652344"
    // end_ty1: 296.363647460937end_ty2: 469.4545593261719end_tx1: 284end_tx2: 62.18181991577148start_tx1: 284start_tx2: 62.18181991577148start_ty1: 296.363647460937start_ty2: 469.4545593261719"
    var isbig = false;
    var startdisx = Math.abs(start_tx2 - start_tx1);//最初的线的距离  220
    var enddisx = Math.abs(end_tx2 - end_tx1);//最后的线的距离 220

    var startdisy = Math.abs(start_ty2 - start_ty1);//最初的线的距离  173
    var enddisy = Math.abs(end_ty2 - end_ty1);//最后的线的距离

    console.log("end------startdisy"+startdisy+"enddisy"+enddisy+"startdisx"+startdisx+"enddisx"+enddisx);

    var scale = getDistancenew(end_tx1,end_tx2,end_ty1,end_ty2)/getDistancenew(start_tx1,start_tx2,start_ty1,start_ty2);//当前的缩放比例是多少
    
    console.log("双指操作的缩放比例是：  "+scale);

    if(scale == lastscale){
        //不变
        return;
    }

    if(scale > lastscale){
        isbig = true;
    }

    if(scale < lastscale){
        isbig = false;
    }

    // if(enddisx > startdisx){//放大
    //     isbig = true;
    // }

    // if(enddisy > startdisy){//放大
    //     isbig = true;
    // }


    console.log("isbig:  "+isbig + "========isviewbig"+isviewbig);
    if(isbig && !isviewbig){//放大
        isviewbig = true;
        changeViewSize();

        start_tx1 = 0;
    }else if(!isbig && isviewbig){//缩小
        isviewbig = false;
        changeViewSize();

        start_tx1 = 0;
    }

    lastscale = scale;
}


function getDistancenew(x1,x2,y1,y2) {
    var x = x2 - x1,
        y = y2 - y1;
    return Math.sqrt((x * x) + (y * y));
};


//判断双指是放大还是缩小
function changeInOrOut(){
    
    isviewbig = !isviewbig;
    console.log("开始关闭视图1:"+isviewbig);
    if(isviewbig){//放大
        isviewbig = true;
        changeViewSize();
    }else{//缩小
        isviewbig = false;
        changeViewSize();
    }
}


//关闭放大的视图
function closeBigView(){
    console.log("开始关闭视图2:"+isviewbig);
    if(isviewbig){
        isviewbig = false;
        changeViewSize();
    }
}

//弹出黑色背景
function showblackbg(){

    $$("#div_words_bg").show();
}

function bigViewTips(){
    native_showdialog("该功能在放大页面时无法使用");
}

//动态改变读书view大小
function changeViewSize(){
    
    if(isviewbig){//读书界面的view放大两倍显示
    
        $("#img_showbig").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_imgtwobig.png");
    
        
        //黑色背景
        $$("#div_words_bg").css("width","200%");
        $$("#div_words_bg").css("height","190%");


            if(position_data.length>0){
                    var strcontent = '';
                    if(isNotNull(position_data) && (position_data.length>=(pageindex+1))){
                    console.log("changeViewSize当前的position_data："+position_data.length + "==当前pageindex"+ pageindex);
                     var position_dataitem = position_data[pageindex];
                     if(isNotNull(position_dataitem)){
                        var imgpath = rootpath+position_dataitem.ImageName;
                        console.log("changeViewSize图片地址"+imgpath);
                         if(isIOS()){
                            imgpath = imgpath + "pg";
                         }
                         strcontent = '<div class="swiper-slide"><img src="'+imgpath+'" alt="" ></div>'
                         // removeAllSlides()
                         $$(".swiper-wrapper").html(strcontent);
                     }
                 }
                     
                     
            }



        // $$("#div_container").css("backgroundColor","red");
        var mySwiper = document.querySelector('.swiper-container').swiper;
        mySwiper.update();

        // var bigw = Number(mySwiper.width)*2;
        // var bigh = Number(mySwiper.height)*2;
        // mySwiper.slides[0].style.height=bigh+'%';
        // mySwiper.slides[0].style.width=bigw+'%';
        $$("#page_container").css("height","90%");
        $$("#div_swipper_container1").css("width","200%");
        $$("#div_swipper_container1").css("height","190%");
        $$("#div_swipper_container2").css("width","100%");
        $$(".swiper-slide").css("width","100%");
        $$(".swiper-slide img").css("width","100%");
        $$("#div_container").css("height","200%");
        $$("#div_container").css("width","200%");

        $$("#body").css("overflow","scroll");
        $$("#body").css("overflow-y","scroll");
        $$("#body").css("overflow-x","scroll");
        $$(".content").css("overflow","scroll");
        $$(".content").css("overflow-y","scroll");
        $$(".content").css("overflow-x","scroll");

        $$("#div_content_bg").css("width","200%");
        $$("#div_content_bg").css("height","190%");
        mySwiper.updateSize();

        mySwiper.allowTouchMove= false;//禁止翻页
        mySwiper.allowSlidePrev= false;//禁止切换上一页
        mySwiper.allowSlideNext= false;//禁止切换下

            beforebigviewindex = pageindex;
            var divs = page_divs[pageindex];
            
            if(isNotNull(divs)){

                for(var i = 0;i<divs.length;i++){
                    var cdiv = divs[i];
                    console.log("输出div参数1："+cdiv.height());
                    // console.log("输出top："+cdiv.top());
                    if(isNotNull(cdiv)){
                        var cwidth = parseFloat(cdiv.attr("cwidth"));
                        var cheight = parseFloat(cdiv.attr("cheight"));
                        var ctop = parseFloat(cdiv.attr("ctop"));
                        var cleft = parseFloat(cdiv.attr("cleft"));
                        console.log("输出div参数2："+cheight);
                        // if(i < Number(curpagenum)){
                            $$(cdiv).css({
                                "width":(cwidth)*100+"%",
                                "height":(cheight)*90+"%",
                                "top":(ctop)*95+"%",
                                "left":(cleft)*100+"%"
                            })
                            // var cctop = $$(cdiv).css("top")*0.9;
                            //  $$(cdiv).css({
                            //     "width":(cdiv.width()),
                            //     "height":(cdiv.height())*0.9,
                            //     "top":cctop,
                            //     "left":($$(cdiv).css("left"))
                            // })
                            console.log("输出div参数3："+cdiv.height());
                        // }
                        
                    }
                }
            }


            


    }else{//读书界面正常显示


        $("#img_showbig").attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/img_imgonebig.png");

        //黑色背景
        $$("#div_words_bg").css("width","100%");
        $$("#div_words_bg").css("height","100%");


        clearBorder();
        console.log("changeViewSize:else:"+position_datastr);
        var mySwiper = document.querySelector('.swiper-container').swiper;
        mySwiper.removeAllSlides();
        mySwiper.destroy(true);
        $$(".swiper-wrapper").html(position_datastr);

        

        initPage();
        // mySwiper.updateSize();
        // mySwiper.updateSlides();
        // mySwiper.update();
        mySwiper = document.querySelector('.swiper-container').swiper;
        mySwiper.slideTo((Number(beforebigviewindex)),0);

        mySwiper.allowTouchMove= true;//keyi 翻页
        mySwiper.allowSlidePrev= true;//禁止切换上一页
        mySwiper.allowSlideNext= true;//禁止切换下一页
        // mySwiper.re
        $$("#page_container").css("height","90%");
        $$("#div_swipper_container1").css("width","100%");
        $$("#div_swipper_container1").css("height","100%");
        $$("#div_swipper_container1").css("padding","0px");
        $$("#div_swipper_container2").css("width","100%");
        $$("#div_swipper_container2").css("height","100%");

        $$(".swiper-slide").css("width","100%");
        $$(".swiper-slide").css("height","100%");
        $$(".swiper-slide img").css("width","100%");
        $$(".swiper-slide img").css("height","100%");
        $$("#div_container").css("height","100%");
        $$("#div_container").css("width","100%");
        $$("#body").css("overflow","hidden");
        $$("#body").css("overflow-y","hidden");
        $$("#body").css("overflow-x","hidden");
        $$(".content").css("overflow","hidden");
        $$(".content").css("overflow-y","hidden");
        $$(".content").css("overflow-x","hidden");

        $$("#div_content_bg").css("width","100%");
        $$("#div_content_bg").css("height","90%");

        // mySwiper.updateSize();

        var divs = page_divs[beforebigviewindex];
            
            if(isNotNull(divs)){
                var checkboderindex = -1;
                if(strs.length >=2 && Number(strs[1])<=divs.length){
                    checkboderindex = Number(strs[1]);
                }
                for(var i = 0;i<divs.length;i++){
                    var cdiv = divs[i];
                    // console.log("当前页面的id："+cdiv.attr("id"));
                    if(isNotNull(cdiv)){
                        var cwidth = parseFloat(cdiv.attr("cwidth"));
                        var cheight = parseFloat(cdiv.attr("cheight"));
                        var ctop = parseFloat(cdiv.attr("ctop"));
                        var cleft = parseFloat(cdiv.attr("cleft"));

                        // if(i < Number(curpagenum)){
                            
                            $$(cdiv).attr("width",(cwidth)*100+"%");
                            $$(cdiv).attr("height",(cheight)*100+"%");
                            $$(cdiv).attr("top",(ctop)*100+"%");
                            $$(cdiv).attr("left",(cleft)*100+"%");

                        // }
                        
                    }

                    if(checkboderindex != -1 && (checkboderindex-1) == i){
                        $$(cdiv).css('border','1px solid #0665A5');
                    }
                }
            }
    }
}


//显示当前播放狂的 border
function showcurcheckbox_border(){
    var divs = page_divs[pageindex];
    if(strs.length >= 2){
        var curcheckpageindexbox = Number(strs[1]);
        var curpageplay = Number(strs[0]);
        var curdiv = divs[curcheckpageindexbox-1];
        if(curdiv != null && curpageplay == pageindex){
            $$(curdiv).css('border','1px solid #0665A5');
        }
    }
}




//比较id的大小，前者大返回 1 ，后者大返回-1，相同返回 0
function compareId(a,b){
    var s_id_a = (a.split("_"))[0];
    var s_id_b = (a.split("_"))[1];
    var e_id_a = (b.split("_"))[0];
    var e_id_b = (b.split("_"))[1];

    if(a == b){
        return 0;
    }

    if(Number(s_id_a) > Number(e_id_a)){
        return 1;
    }

    if((Number(s_id_a) == Number(e_id_a)) && 
        (Number(s_id_b) > Number(e_id_b)) ){
        return 1;
    }

return -1;

}
